module pe.app.loading {
/** * Backing file loading screen. * This class is ViewModel bound to DOM with Knockout.js. * Parametrized with an ArrayBuffer loading function (async)* and a scheduler that can yield.
*/export class LoadFile {
className = ko.observable('');
shortText = ko.observable('');
progressRatio = ko.observable(0);
private static _loadWorkPart = 0.2;
constructor(arrayBufferSource: (callback: AsyncCallback<ArrayBuffer>) => void,
yieldScheduler: AsyncCallback.YieldCallback) {
var callback: any = (error, arrayBuffer) =>
this._arrayBufferComplete(error, arrayBuffer);
callback.progress = (current, total, text = this.shortText()) => {
this.progressRatio(LoadFile._loadWorkPart * current / total);
this.shortText(text);
};
this.className('pe-loading-getdata');
this.shortText('wait');
this.progressRatio(0);
arrayBufferSource(callback);
}
private _arrayBufferComplete(error: Error, arrayBuffer: ArrayBuffer) {
if (error) {
this.className('pe-loading-error');
this.progressRatio(1);
this.shortText(error.message);
return;}
this.className('pe-loading-unmanaged');
this.shortText('PE headers');
this.progressRatio(LoadFile._loadWorkPart);
//TODO: read PE headers, then read Assembly}
}
}